﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

class VersionsInAction
{
    [MyVersion("1")]
    public static void FirstSampleMethod()
    {
        Console.WriteLine("This is the first sample method.");
    }

    [MyVersion("1.12", "Sample greeting.")]
    public static void HelloWorld()
    {
        Console.WriteLine("Hello, World!");
    }

    [MyVersion("2", "Absolutely pointless method.")]
    public int GetFive()
    {
        return 5;
    }

    public static void Main()
    {
        Type classType = typeof(VersionsInAction);
        MethodInfo[] methods = classType.GetMethods();
        foreach (MethodInfo method in methods)
        {
            object[] attributes = method.GetCustomAttributes(false);
            foreach (Attribute ver in attributes)
            {
                if (ver is MyVersionAttribute)
                {
                    MyVersionAttribute atr = ver as MyVersionAttribute;
                    Console.WriteLine("Method {0} is version {1} and has comment: {2}",
                        method.Name, atr.VersionName, atr.Comment);
                }
            }
        }
    }
}
